<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%
	String baseP = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ "/";
%>
<!doctype html>
<html>
<head>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setDateHeader("Expires", -10);
%>
<title>办事指南</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta http-equiv="cleartype" content="on" />
<link rel="shortcut icon" href="/nocontent" />
<script type="text/javascript" src="<c:url value='/resource/js/jquery-1.11.0.min.js'/>" ></script>
<script type="text/javascript" src="<c:url value='/resource/js/iscroll.js'/>" ></script>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="apple-touch-fullscreen" content="yes">
<meta name="viewport" content="width=device-width,user-scalable=no" />
<meta name="viewport" id="viewport" />
<link rel="stylesheet" href="<c:url value='/resource/css/mobiscroll.android-ics-2.5.2.css'/>" />
<link rel="stylesheet" href="<c:url value='/resource/css/mobiscroll.core-2.5.2.css'/>" />
<script type="text/javascript" src="<c:url value='/resource/js/jquery-1.11.0.min.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resource/js/mymobiscroll.core-2.5.2.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resource/js/mobiscroll.datetime-2.5.1.js'/>"></script>
<script type="text/javascript" src="<c:url value='/resource/js/mobiscroll.select-2.5.1.js'/>"></script>
<link rel="stylesheet" href="<c:url value='/resource/js/polices/smatters.css'/>" />
<link rel="stylesheet" href="<c:url value='/resource/js/polices/scrollbar.css'/>" />
<link type="text/css" rel="stylesheet" href="<c:url value='/resource/css/main.css'/>">
</head>
<body class="body_bg">
	<div class="">
		<div class="home_logo"> <img src="<c:url value='/resource/images/theme/3/images/logo.png'/>"/> </div>
		<div class="list_search">
			<div style="margin-left:8px;">
				<input type="hidden" id="pageIndex">
				<select id="xq" onchange="GetXq()">
					<optgroup label="辖区">
						<option value="">辖区</option>
					</optgroup>
					<optgroup label="苏州市局">
						<option id="szsj" value="-1">苏州市局</option>
					</optgroup>
				</select>
				<select id="jz" onchange="GetJz()"></select>
				<select id="fl" onchange="GetFl()" style="width: 10px">
					<option value="">分类</option>
					<option value="0">企业</option>
					<option value="1">个人</option>
				</select>
				<span onclick="que()" id="sx_dummy">筛选</span>
				<!-- <input type="text" value="筛选" readonly="readonly" onclick="que()" id="sx_dummy"> -->
			</div>
		</div>
		
		<div id="wrapper">
			<div id="scroller">
				<div id="pullDown">
					<span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
				</div>
				<ul id="newsList">
				</ul>
				<div id="pullUp" style="display: none;">
					<span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载更多...</span>
				</div>
				<div id="pullUpIcon" style="display: none;">
					<span class="pullUpIcon" style="width:100%;display: block; background: none;border:0px; text-align: center;"></span><span class="pullOver" style="width:100%; display: block;background: none;border:0px; text-align: center;">无更多数据!</span>
				</div>
				<div id="nodata" style="display: none;width:100%;background: none;border:0px; text-align: center;">
					<span class="pullUpIcon" style="width:100%;display: block; background: none;border:0px; text-align: center;"></span><span class="pullOver" style="width:100%; display: block;background: none;border:0px; text-align: center;">没找到相关数据!</span>
				</div>
			</div>
		</div>
	</div>
	
	<div id="shadow" class="shade" style="display:none;"></div>
	<div id="pop" class="popup" style="display:none">
		<div class="popup_tit">请输入事项名称的关键字</div>
		<div class="popup_main">
			<span class="rt"><input type="text" id="key" placeholder="请输入关键字" /> </span>
		</div>
		<div class="queryIn">
			<input type="button" placeholder="筛选" value="筛选" class="submit" /> 
			<input type="button" placeholder="关闭" value="关闭" class="submit02" id="close" />
		</div>
	</div>
	<input type="hidden" id="bureaus" value="-1">
	<script type="text/javascript">
		function que() {
			$("#pop").show();
			$("#shadow").show();
			$("#key").val("");
		}
	</script>
	<script type="text/javascript">
		var myScroll, pullDownEl, pullDownOffset, pullUpEl, pullUpOffset, generatedCount = 0;

		function pullDownAction() {
			setTimeout(function() {
				loaddata(1);
				myScroll.refresh();
			}, 100);
		}

		function pullUpAction() {
			setTimeout(function() {
				var page = $("#pageIndex").val();
				page++;
				loaddata(page);
				myScroll.refresh();
			}, 100);
		}

		/**
		 * 初始化iScroll控件
		 */
		function loaded() {
			pullDownEl = document.getElementById('pullDown');
			pullDownOffset = pullDownEl.offsetHeight;
			pullUpEl = document.getElementById('pullUp');
			pullUpOffset = pullUpEl.offsetHeight;
			myScroll = new iScroll('wrapper',
					{
						//scrollbarClass : 'myScrollbar', /* 重要样式 */
						useTransition : false, /* 此属性不知用意，本人从true改为false */
						topOffset : pullDownOffset,
						onRefresh : function() {
							if (pullDownEl.className.match('loading')) {
								pullDownEl.className = '';
								pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
							} else if (pullUpEl.className.match('loading')) {
								pullUpEl.className = '';
								pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
							}
						},
						onScrollMove : function() {
							if (this.y > 5 && !pullDownEl.className.match('flip')) {
								pullDownEl.className = 'flip';
								pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
								this.minScrollY = 0;
							} else if (this.y < 5 && pullDownEl.className.match('flip')) {
								pullDownEl.className = '';
								pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
								this.minScrollY = -pullDownOffset;
							} else if (this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
								pullUpEl.className = 'flip';
								pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
								this.maxScrollY = this.maxScrollY;
							} else if (this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
								pullUpEl.className = '';
								pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
								this.maxScrollY = pullUpOffset;
							}
						},
						onScrollEnd : function() {
							if (pullDownEl.className.match('flip')) {
								pullDownEl.className = 'loading';
								pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
								pullDownAction(); // Execute custom function (ajax call?)
							} else if (pullUpEl.className.match('flip')) {
								pullUpEl.className = 'loading';
								pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
								if ($("#pullUp").is(":hidden")) {
									return false;
								}
								pullUpAction(); // Execute custom function (ajax call?)
							}
						}
					});

			setTimeout(function() {document.getElementById('wrapper').style.left = '0';}, 800);
		}

		//初始化绑定iScroll控件 
		document.addEventListener('touchmove', function(e) {e.preventDefault();}, false);
		document.addEventListener('DOMContentLoaded', loaded, false);
	</script>
	<script type="text/javascript">
		var init = 0;
		var sid = "${sid}";
		var fid = "${fid}";
		
		$(function() {
			$("#key").val("");
			$("#close").click(function() {
				$("#pop").hide();
				$("#shadow").hide();
			});
			$(".submit").click(function() {
				$("#pop").hide();
				$("#shadow").hide();
				loaddata(1);
			});
			//获取辖区
			$.ajax({
					url : "http://221.224.13.5:8190/econsole/api/query/police-bureaus",
					type : "get",
					timeout : 6000,
					async : false,
					success : function(data) {
						$.each(data["data"], function(k, v) {
							getFj(v.Id, v.Name);
						});
						init++;
					},
					error : function(XMLHttpRequest, textStatus,errorThrown) {
						alert(errorThrown);
					}
				});

			//遍历全部警钟
			$.ajax({
					url : "http://221.224.13.5:8190/econsole/api/query/police-catalogs",
					type : "get",
					timeout : 6000,
					async : false,
					success : function(data) {
						var htmlArr = "";
						var resultData = data['data'];
						if (resultData) {
							var htmlArr = "<option value=''>警种</option>";
							for ( var i = 0; i < resultData.length; i++) {
								htmlArr += '<option value="' + resultData[i]['ID'] + '">'
										+ resultData[i]["Name"]
										+ '</option> ';
							}
						}
						$("#jz").html("").append(htmlArr);
						//警种
						$("#jz").val(sid);
						$("#jz").val(sid).scroller('destroy').scroller({
									preset : "select",
									theme : "android-ics light",
									mode : "scroller",
									display : "modal",
									group : true,
									width : 180,
									rows : 5,
									setText : '确定',
									cancelText : '取消',
									showLabel : false,
									useShortLabels : false
								});
						init++;
					},
					error : function(XMLHttpRequest, textStatus,
							errorThrown) {
						alert(errorThrown);
					}
				});
			//分类
			$("#fl").val("").scroller('destroy').scroller({
				preset : "select",
				theme : "android-ics light",
				mode : "scroller",
				display : "modal",
				group : true,
				width : 180,
				rows : 5,
				setText : '确定',
				cancelText : '取消',
				showLabel : false,
				useShortLabels : false
			});
			ininAction();
		});

		function ininAction() {
			if (init >= 2) {
				$("#xq").val(fid);
				$("#xq").val(fid).scroller('destroy').scroller({
					preset : "select",
					theme : "android-ics light",
					mode : "scroller",
					display : "modal",
					group : true,
					width : 180,
					rows : 5,
					setText : '确定',
					cancelText : '取消',
					showLabel : false,
					useShortLabels : false
				});
				if("-1" == "${bureaus }"){
					$("#szsj").attr("selected", "selected");
					$("#xq_dummy").val(subStr($("#szsj").text()));
				}
				loaddata(1);
			} else {
				window.setTimeout(ininAction, 500);
			}
		}
		
		function putObj(key, data, expireSeconds) {
		          var obj = {"key": key, "data": data, "expire": (new Date().getTime() + expireSeconds * 1000)};
		          sessionStorage.setItem(key, JSON.stringify(obj));
		}

		//缓存
        function getObj(key) {
            var _item = sessionStorage.getItem(key);
            if (_item) {
                var obj = JSON.parse(_item);
                //判断是否过期，如果过期则返回null
                var _now = new Date().getTime();
                if (_now <= obj.expire) {
                    return obj;
                }
                return null;
            }
            return null;
        }
		
		//分局
		function getFj(id, na, select1) {
			$.ajax({
					url : "http://221.224.13.5:8190/econsole/api/query/bureau-depts/" + id,
					type : "get",
					timeout : 6000,
					async : false,
					success : function(data) {
						var htmlArr = "<optgroup id='"+id+"' label=" + na + ">";
						
						htmlArr += "<option value=" + id+">" + na + "</option>";
						$.each(data["data"], function(k, v) {
							htmlArr += "<option value='"+v.Id+"'>" + v.Name + "</option>";
						});
						
						htmlArr += "</optgroup>";
						$("#xq").append(htmlArr);
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						alert(errorThrown);
					}
				});
		}
		
		//辖区
		function GetXq() {
			$("#key").val("");
			$("#xq_dummy").val(subStr($("#xq option:selected").text()));
			loaddata(1);
			myScroll.refresh();
			myScroll.scrollTo(0, 100, 200);
		}
		
		//警种 全部
		function GetJz() {
			$("#key").val("");
			$("#jz_dummy").val($("#jz option:selected").text());
			loaddata(1);
			myScroll.refresh();
			myScroll.scrollTo(0, 100, 200);
		}
		
		//分类
		function GetFl() {
			loaddata(1);
			myScroll.refresh();
			myScroll.scrollTo(0, 100, 200);
		}
		
		function subStr(str){
			if(!str)
				return;
			
			if(str.length<=4)
				return str;
			
			return str.substr(0,3)+"..";
		}
		
		//查询出所有事项
		function loaddata(page) {
			var name = $("#xq_dummy").val();
			if (name == "全部" || name == "") {
				$("#bureaus").val("");
			} else if (name == "苏州市局") {
				$("#bureaus").val("-1");
			} else {
				$("#bureaus").val("2");
			}
			$("#pageIndex").val(page);
			var xq = $("#xq").val();
			var jz = $("#jz").val();
			var fl = $("#fl").val();
			var key = $("#key").val();
			var name = $("#xq_dummy").val();
			$("#xq_dummy").val(subStr($("#xq option:selected").text()));
			var bureaus = $("#bureaus").val();
			if (xq == null || xq == "" || xq == "-1") {
				xq = "";
			}
			if (jz == null) {
				jz = "";
			}
			if (fl == null) {
				fl = "";
			}
			$.ajax({
					url : 'http://221.224.13.5:8190/econsole/api/matters/page/case?policeId=&pageSize=10&keyword='
							+ key
							+ '&catalog='
							+ jz
							+ '&subject='
							+ fl
							+ '&bureausId='
							+ xq
							+ '&type='
							+ bureaus
							+ '&pageIndex=' + page,
					type : 'get',
					async : false,
					success : function(data) {
						var listLi = $("#newsList");
						if(page == "1"){
							listLi.empty();
						}
						if (!data["succ"]) {
							$("#pullUp").hide();
							$("#pullUpIcon").hide();
							$("#nodata").show();

						} else {
							$("#nodata").hide();
							var allpage = data["data"].totalPage;
							if (allpage == page) {
								$("#pullUp").hide();
								$("#pullUpIcon").show();
							} else {
								$("#pullUp").show();
								$("#pullUpIcon").hide();
							}

							$.each(data["data"].list,function(k, v) {
												if (v.Name == "苏州市公安局") {
													bureaus = "1";
												} else {
													bureaus = "2";
												}
												if (v.ProjectCaseName.length > 15) {
													v.ProjectCaseName = v.ProjectCaseName.substring(0,15)
															+ "...";
												}
												var url = "/econsole/api/police/matters?dept_type="+bureaus+"&dept_id="+v.ProjectCaseDepGuid+"&matterId="+v.ProjectCaseGuid+"";
												var _tr=$("<li><a href=\""+url+"\"><p class=\"sup\">"+v.ProjectCaseName+"</p><p class=\"sub\">受理单位："+v.Name+"</p></a></li>");
												listLi.append(_tr);
											});

						}
					},
					cache : false,
					timeout : 5000,
					error : function(textStatus, errorThrown) {
						alert("超时");
					},
				});
		}
	</script>
</body>
</html>